home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack / ssh-insertion-attack.txt < prev    next >
Encoding:
Text File  |  1998-11-07  |  31.5 KB  |  811 lines

  1. -------------------------------------------------------------------------------
  2.  
  3.                             
  4.                               CORE SDI S.A.
  5.                           Buenos Aires, Argentina
  6.                          <http://www.core-sdi.com>
  7.              
  8.  
  9.                            Security Advisory
  10.                             June 11th, 1998                       
  11.  
  12.                           SSH insertion attack
  13.                                            
  14. -------------------------------------------------------------------------------
  15.  
  16.  
  17.   This advisory addresses a vulnerability present in the SSH software
  18.   package that allows an attacker to execute arbitrary commands on the 
  19.   SSH server or otherwise subvert an encrypted SSH channel with
  20.   arbitrary data.
  21.  
  22. Problem Description
  23. ~~~~~~~~~~~~~~~~~~~
  24.   
  25.   SSH (Secure Shell) is a program that provides strong authentication and 
  26.   secure communications over insecure channels.
  27.   Its widely used for logging in to remote computers, file transfers and
  28.   tunneling of other protocols over the encrypted comunications channel.
  29.   All communications are automatically and transparently encrypted.
  30.   Encryption is also used for integrity checking purposes although 
  31.   current implementations rely on a 32 bit Cyclic Redundancy Check
  32.   to perform integrity checks after the decryption of an incoming packet.
  33.  
  34.   Encryption is done using one of a list of supported algorithms that
  35.   is exchanged between client and server.
  36.   Upon conection establishment client and server perform a protocol
  37.   negotiation that includes mutual authentication, selection
  38.   of a cipher supported by both ends for subsequent communications and
  39.   of a session key to be used with the cipher. Encryption is then
  40.   turned on using the selected cipher and session key, all further 
  41.   communications are encrypted.
  42.  
  43.   Currently supported ciphers are:
  44.  
  45.   - Blowfish
  46.     Bruce Schneier's block cipher using a 128 bit key 
  47.   - IDEA
  48.     A 128 bit block cipher 
  49.   - DES
  50.     The Data Encryption Standard 56-bit block cipher
  51.   - Triple DES (3DES)
  52.     A three-key triple-DES algorithm with an effective key lenght
  53.     of 112 bits.
  54.   - ARCFOUR
  55.     An RC4 compatible stream cipher using a 128 bit key
  56.  
  57.    The use of these algorithms in CBC (Cipher Block Chaining) or
  58.    CFB (Cipher Feedback 64 bits) modes with the CRC-32 integrity check
  59.    allows to perform a known plaintext attack (with as few as
  60.    16 bytes of known plaintext) that permits the insertion of encrypted
  61.    packets with any choosen plaintext in the client to server stream
  62.    that will subvert the integrity checks on the server and decrypt to
  63.    the given plaintext, thus allowing an attacker to execute arbitrary
  64.    commands on the server.
  65.    The attack is equally feasible on the server to client stream ,
  66.    although it just gives the ability to send arbitrary data the
  67.    user's terminal. The implications of such an attack are probably not
  68.    as severe as an attack to the server side of the connection but
  69.    must be taken in consideration in the process of applying fixes.
  70.  
  71. Technical details
  72. ~~~~~~~~~~~~~~~~
  73.  
  74.    After the protocol identification phase, where the server
  75.    sends a plaintext string specifiying its the protocol and software 
  76.    versions, all communication is done encapsulating data in a
  77.    packet format described as 'The Binary Packet Protocol' [1]
  78.    The packet layout is as follows:
  79.  
  80.               32         24        16         8         0
  81.                +----------+---------+---------+---------+
  82.                |        data length (bytes)             |
  83.                +----------+---------+---------+---------+
  84.                |       1 to 8 bytes of padding          |
  85.                =                                        =
  86.                +----------+---------+---------+---------+
  87.                |   type   |                             |
  88.                +----------+                             +
  89.                |                                        |
  90.                =                 data                   =
  91.                |                                        |
  92.                +----------+---------+---------+---------+
  93.                |                CRC-32                  |
  94.                +----------+---------+---------+---------+
  95.  
  96.  
  97.    Data length: Length in bytes of the given packet, not including 
  98.                 the length field and padding 
  99.    Padding    : 8 - (length mod 8) bytes of random data, putting
  100.                 random data at the beginning of the packet is an 
  101.                 effort to make known plaintext attacks more difficult.
  102.    Packet type: An 8-bit unsigned byte.
  103.    Data       : length - 5 data bytes
  104.    CRC-32     : the four 8-bit check bytes, MSB first. The CRC is
  105.                 computed before any encryption
  106.                            
  107.   Encryption is done on the padding+type+data+CRC fields, the length
  108.   field is never encrypted. The encrypted portion of the packet has
  109.   a length that is always a multiple of 8 bytes.
  110.  
  111.   Knowning certain characteristics of the cipher modes  being used,
  112.   i.e. CBC, with a known plaintext an attacker is able to build a
  113.   custom SSH packet (i.e. a type SSH_CMSG_STDIN_DATA packet) with
  114.   the padding bytes computed in a way such that the next 8-bytes
  115.   of the encrypted data will decrypt to arbitrary plaintext. In
  116.   this particular case, the decrypted data will correspond to the
  117.   type field and 7 data bytes. 
  118.   After the 16 bytes (padding+type+7 data bytes) the attacker would
  119.   include a variable length of data bytes specifically crafted to
  120.   produce a valid CRC-32 field for the whole packet once it is
  121.   decrypted.
  122.   This attack and several variations using the same technique can
  123.   be performed due to the usage of weak integrity check schemes, in
  124.   particular CRC-32 has certain properties that allows the attacker
  125.   to forge a valid CRC for her corrupted packet.
  126.  
  127.   However, for the attack to succeed the attacker must be able to
  128.   perform an active network attack, by either intercepting the
  129.   legit SSH connection at any point between the client and server and
  130.   injecting a forged packet or by performing a TCP session hijack attack.
  131.   Such an attack is described in [6] and for SSH the two methods of
  132.   TCP desynchronization can be used. In particular the method described
  133.   as "Null data desynchronization" can be carried out using packets of
  134.   type SSH_CMSG_IGNORE.
  135.  
  136.   Note that the new revision for the SSH protocol, proposed and
  137.   published as Internet Drafts [2],[3],[4] [5] makes use of
  138.   cryptographycally strong message authentication codes for
  139.   integrity checks that wont fail to these attacks. 
  140.   
  141.   Its is important to mention that despise the vulnerabilities
  142.   found in the SSH protocol, it still remains to be a much more
  143.   secure alternative to telnet, rsh and rlogin applications.
  144.  
  145.  
  146.   [1] "The SSH (Secure Shell) Remote Login Protocol", T. Ylonen
  147.        Helsinki University of Technology. November 15th 1995
  148.            (draft expired on May 15th, 1996)
  149.  
  150.            Included as the file ./RFC in the ssh distribution
  151.            <http://www.cs.hut.fi/ssh>
  152.  
  153.   [2] "SSH Protocol Architecture", draft-ietf-secsh-architecture-01.txt.gz
  154.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  155.  
  156.   [3] "SSH Connection Protocol", draft-ietf-secsh-connect-03.txt.gz
  157.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  158.  
  159.   [4] "SSH Authentication Protocol", draft-ietf-secsh-userauth-03.txt.gz
  160.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  161.  
  162.   [5] "SSH Transport Layer Protocol",draft-ietf-secsh-transport-03.txt.gz
  163.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  164.    
  165.            (drafts expired on May 7th, 1998)
  166.  
  167.   All Internet drafts are available at <ftp://ftp.isi.edu/internet-drafts/>
  168.  
  169.   [6] "Simple Active Attack Against TCP", Laurent Joncheray, 
  170.       Merit Networks Inc., 5th USENIX Security Simposium. 1995.
  171.  
  172.  
  173. Impact:
  174. ~~~~~~
  175.    An attacker with access to the encrypted SSH stream may insert
  176.    encrypted blocks in the stream that will decrypt to 
  177.    arbitrary commands to be executed on the SSH server.
  178.  
  179. Fix Information:
  180. ~~~~~~~~~~~~~~~
  181.    
  182.    Upgrade to the upcoming SSH protocol version 2.
  183.  
  184.    Commercial F-Secure SSH users contact Data Fellows Inc. for
  185.    information on how to upgrade to F-Secure 2.0
  186.  
  187.    Notice that version 2 of the SSH protocol is not 
  188.    compatible with the previous version, thus you
  189.    will need to upgrade all the SSH clients as well.
  190.    
  191.    In the meantime, upgrade to version 1.2.25 of SSH, which
  192.    fixes the problem. The SSH 1.2.25 distribution can be 
  193.    obtained from:
  194.    
  195.     <ftp://ftp.cs.hut.fi/pub/ssh/ssh-1.2.25.tar.gz>
  196.  
  197.    F-Secure SSH version 1.3.5 fixes this security problem.
  198.    If you are using the commercial Data Fellows SSH package and you
  199.    have a support contract, you can obtain the 1.3.5 from your local
  200.    retailer.
  201.  
  202.    Users without a support contract can obtain a patch which fixes 
  203.    this problem from:
  204.  
  205.     <http://www.DataFellows.com/f-secure/support/ssh/bug/su134patch.html>.
  206.  
  207.    A patch for the free SSH 1.2.23 distribution and the complete
  208.    SSH 1.2.23 package, with the patch applied, can be obtained at:
  209.  
  210.             <http://www.core-sdi.com/ssh>
  211.  
  212.   Below  are the MD5 hashes for the provided files
  213.  
  214.    MD5 (ssh-1.2.23.patch) = 6bdb63d57f893907191986c5ced557ab
  215.    MD5 (ssh-1.2.23-core.tar.Z) = fffb52122aae26c1f212c051a305a310
  216.    MD5 (ssh-1.2.23-core.tar.gz) = f9509ba0f0715637805c6b116adc0869
  217.  
  218.  
  219. Vulnerable Systems:
  220. ~~~~~~~~~~~~~~~~~
  221.  
  222.    All systems running implementations of SSH using protocol version 1.x
  223.    are vulnerable.
  224.    This includes SSH software versions up to 1.2.23 and F-Secure SSH 1.3.4
  225.    
  226.    To obtain the version of the SSH server that is running
  227.    on a given host you can issue the following commands:
  228.    
  229.  
  230.    $ telnet <IP address> 22
  231.    Trying <IPaddress>...
  232.    Connected to <IPaddress>.
  233.    Escape character is '^]'.
  234.    SSH-1.5-1.2.23
  235.        \ / \--------- software version
  236.         |------------ protocol version
  237.  
  238.    ^]
  239.    telnet> close
  240.    Connection closed.
  241.    $ exit
  242.  
  243.      
  244. Additional Information:
  245. ~~~~~~~~~~~~~~~~~~~~~~
  246.   
  247.    These vulnerabilities were discovered by Ariel Futoransky
  248.    <futo@core-sdi.com> and Emiliano Kargieman <ek@core-sdi.com>
  249.  
  250.    CORE SDI wishes to thank the SSH maintainers Tatu Ylonen <ylo@ssh.fi>
  251.    and Tero Kivinen <kivinen@ssh.fi> for their quick response to the
  252.    issues rised by this advisory.
  253.    
  254.    Olli Voima <olli.voima@DataFellows.com> of Data Fellows Inc. 
  255.    provided the fix information for the F-Secure products.
  256.    
  257.    Comments and questions regarding this advisory should be sent to:
  258.  
  259.            Ariel Futoransky <futo@core-sdi.com> 
  260.            Emiliano Kargieman <ek@core-sdi.com>
  261.  
  262.    For more information about CORE SDI S.A.  contact <core@core-sdi.com>
  263.    or visit <http://www.core-sdi.com>
  264.         
  265.    You can contact CORE SDI S.A. at <corelabs@core-sdi.com> using the
  266.    the following PGP key:
  267.  
  268. Type Bits/KeyID    Date       User ID
  269. pub  1024/CF4E0CF5 1998/05/18 CORELABS <corelabs@core-sdi.com>
  270.  
  271. -----BEGIN PGP PUBLIC KEY BLOCK-----
  272. Version: 2.6.3ia
  273. Comment: Requires PGP version 2.6 or later.
  274.  
  275. mQCNAzVgfMgAAAEEAJSfJNdvCwIAc4AK0ckeimubLIwzsRVDRhjPQIOYt/7kxxio
  276. DZybr53fwMEjyT8cHXRL08i0R9rcuFeCNAez6XcalbhqUKXDcLL/cZK80CCDSCs5
  277. tRCZGGOEBnXQIoyvbvi4gNYhBS5wUvmh3b/mvRFTvhmRrUy9m/nO/LnPTgz1AAUR
  278. tCBDT1JFTEFCUyA8Y29yZWxhYnNAY29yZS1zZGkuY29tPokAlQMFEDVgfMn5zvy5
  279. z04M9QEBC6ED/0Szt3f54JTvkZG3ezQ8G60HvAw4/A5Ti6i3oze6jsXxzGp6pA1x
  280. i0jaZpKaUSpo0MLc7BcijMKneuUHnN3XtN5YxtFt0aEoot1MIvv4BsdeUb3x257G
  281. 3+vr8SxGk44Vm4tfuN8F/2dNo/00yYP9rd3zQ8Tl+gmr5VxnLViZIDuh
  282. =ulRg
  283. -----END PGP PUBLIC KEY BLOCK-----
  284.  
  285. Copyright Notice:
  286. ~~~~~~~~~~~~~~~~
  287. The contents of this advisory are Copyright (C) 1998 CORE SDI S.A.,
  288. and may be distributed freely provided that no fee is charged for
  289. this distribution, and proper credit is given.
  290.  
  291.  
  292. $Id: ssh-advisory.txt,v 1.8 1998/06/11 22:05:03 iarce Exp $
  293.  
  294. -------------------------------------------------------------------------------
  295.  
  296.  
  297.                               CORE SDI S.A.
  298.                           Buenos Aires, Argentina
  299.                          <http://www.core-sdi.com>
  300.  
  301.  
  302.                             General Description
  303.                                July 3rd, 1998
  304.  
  305.                            SSH insertion attack 
  306.  
  307. --------------------------------------------------------------------------------
  308.  
  309.  
  310. Crc32 Compensation attack against ssh-1.5
  311. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  312.  
  313. This file gives a general description of the construction of a crc compensation
  314. attack against SSH protocol version 1.5. More information on the scope and 
  315. characteristics of this attack, and the original advisory is available at 
  316. <http://www.core-sdi.com/ssh>
  317.  
  318. The attacker is assumed to have active access to the network where the
  319. cipherstream travels.  She doesnt know neither the private server keys,
  320. nor the simetric session key.
  321.   The server is trusted, it wont reveal private information and wont give
  322. any direct access to the attacker.  
  323.   These attacks works for any authentication method used because they are
  324. done after the authentication phase of the protocol negotiation.
  325.  
  326.  
  327. 1. Feedback modes
  328. ~~~~~~~~~~~~~~~~~
  329.  
  330. SSH is currently using two different feedback modes for its block ciphers: 
  331. Cipher FeedBack (CFB) and Cipher Block Chaining (CBC).
  332.   The feedback is applied in the same way in every cipher algorithm
  333. SSH uses.
  334.   An Initialization Vector is not negotiated in the SSH protocol and an
  335. IV of all zeros is used.
  336.  
  337. Cipher block chaining is:
  338.  
  339.     Ci = Ek ( Pi xor Ci-1 )
  340.     Pi = Dk ( Ci ) xor Ci-1
  341.  
  342. CFB-64 is:
  343.  
  344.     Ci = Ek ( Ci-1) xor Pi
  345.     Pi = Ek ( Ci-1) xor Ci
  346.  
  347. Ci = ith block of the cipher stream.
  348. Pi = ith block of the plain stream.
  349. Ek(x) = Encryption of block x using k as key.
  350. Dk(x) = Decryption of block x using k as key.
  351. C0 = IV
  352.  
  353.  
  354. The use of the feedback strengthens the way the block cipher is used randomizing
  355. its input and reducing the information an eavesdropper can get from
  356. repeated plaintext blocks. 
  357.   However, using this feedback modes doesnt protect the protocol against
  358. replay-attacks or cut-and-paste. If the blocks C1..Cj are inserted in
  359. cipher stream, block C1 will be decrypted to garbage, and blocks C2..Cj
  360. will be decrypted to P2..Pj.
  361.  
  362. If an active eavesdropper knows some block of the plaintext stream, he
  363. may insert any block using the ciphertext stream. 
  364.   The attacker knows the ciphertext stream C1..Cj and she knows also that Ci 
  365. will decrypt to a particular Pi due to protocol characteristics. Now, since
  366. the attacker has the Ci/Pi known-plaintext pair and assuming that X is any
  367. arbitrary block the attacker may choose, she may insert the following blocks: 
  368.  
  369.  
  370. CBC:
  371. ===
  372. Cj+1 = X
  373. Cj+2 = Ci
  374.  
  375. And will be decrypted to
  376. Pj+1 = Cj Xor Dk(X) = ?
  377. Pj+2 = X Xor Dk(Ci) = X Xor Ci-1 Xor Pi
  378.  
  379. CFB:
  380. ===
  381. Cj+1 = Ci-1
  382. Cj+2 = X
  383.  
  384. And will be decrypted to
  385. Pj+1 = Ci-1 Xor Ek(Cj) =  ?
  386. Pj+2 = X Xor Ek(C-1) = X Xor Pi Xor Ci
  387.  
  388. The attacker cant control whats in Pj+1, but she can insert any block at
  389. Pj+2 because she controls X.
  390.  
  391. It should be considered also that for CBC modes, the IV is plain XORed
  392. to the first block, although the IV is always zero and cannot be
  393. modified. For CFB-64, the last block is plain XORred to the encription of
  394. its previous block and can be modified in an easy manner.
  395.  
  396.  
  397. 2. Checksum
  398. ~~~~~~~~~~~
  399. SSH-1.5 protocol includes a checksum field within each packet that
  400. incorporates redundancy that allows the receiver of the packet to verify
  401. the integrity and authenticity of the packet with a defined threshold of
  402. 2^-32.
  403.   CRC32, the integrity function, is a linear function in Z2-spaces, the 
  404. remainder from the division of the input stream (as a polinomy in Z2)
  405. with the constant polinomy: 
  406.  
  407.  (X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0)
  408.  
  409. As a result of this definition, the following propierties hold:
  410.  
  411.     Crc32(A Xor B) = Crc32(A) Xor Crc32(B)
  412.     Crc32('0' + A) = Crc32(A)
  413.          If Crc32(A) = 0  Then Crc32(A + '0') = 0
  414.  
  415. ( '+' in this context means concatenate. '0' means one 0 Bit)
  416.  
  417.  
  418. 3. Packet
  419. ~~~~~~~~~
  420. SSH-1.5 defines the following packet format:
  421.  
  422.               32         24        16         8         0
  423.                +----------+---------+---------+---------+
  424.                |        data length (bytes)             |
  425.                +----------+---------+---------+---------+
  426.                |       1 to 8 bytes of padding          |
  427.                =                                        =
  428.                +----------+---------+---------+---------+
  429.                |   type   |                             |
  430.                +----------+                             +
  431.                |                                        |
  432.                =                 data                   =
  433.                |                                        |
  434.                +----------+---------+---------+---------+
  435.                |                CRC-32                  |
  436.                +----------+---------+---------+---------+
  437.  
  438. Datalen is unencrypted, the rest is encrypted with the selected
  439. blockcipher and feedback mode. The last block of the previous packet is
  440. used in the feedback. The padding is added to make the packet size be a
  441. multiple of 64-bits, and to include at least one padding byte. The crc32
  442. is applied to padding, type and data.
  443.  
  444. Within a packet, there are two message types that are of particular interest 
  445. and could be directly used in an attack: SSH_STDIN_DATA and SSH_STDOUT_DATA, as 
  446. defined in [1]. These type of messages has the following message structure:
  447.  
  448. +-------+------------------------+---------------------------------------------+
  449. | TYPE  | 32-Bit Message Length  |                    Message data             |
  450. +-------+------------------------+---------------------------------------------+
  451.  
  452. SSH closes the connection if:
  453.     A) The crc-32 field is not consistent with the packet
  454.     pad/type/data.
  455.     B) The 32-bit message len is not equal to the packet len minus
  456.     fields.
  457.     C) The message type is invalid
  458.  
  459. Within a single cipher block fits:
  460.     + 1 Byte type field
  461.     + 4 Bytes Message length
  462.     + 3 Bytes data
  463.  
  464.  
  465. 4. ATTACK
  466. ~~~~~~~~~
  467. A)
  468.  
  469. The last block of the packet looks like:
  470.  
  471. +---------+--------+--------+--------+----------+---------+---------+---------+
  472. |            LAST 4 BYTES            |                CRC-32                  |
  473. +---------+--------+--------+--------+----------+---------+---------+---------+
  474.  
  475. If CFB-64 is used, the last ciphered block Cj, is not encrypted using
  476. the blockcipher but is plain XORed to Ek(Cj-1).
  477.   Given that Crc(A XOR B) = Crc(A) XOR Crc(B), an attacker may replace the
  478. last block of the packet in the cipherstream with the XOR of the
  479. existing block and 8-bytes block with a valid crc.
  480.   Because of the linear characteristics of crc32 the packet will have a
  481. valid crc.
  482.   The last four bytes of the data field in a packet could be modified by
  483. an attacker in an easy way.
  484.  
  485. If the attacker knows what is in the last four bytes of the data field, she 
  486. may replace them with arbitrarily choosen bytes.
  487.  
  488. B) If CBC mode is used, and an attacker have two Pi/Ci
  489. known-plaintext/ciphertext blocks she may follow the following steps
  490. creating a new valid packet that could be inserted in the stream
  491. regardless of the blockcipher and key used. 
  492.   The known plaintext/ciphertext pair is Pi/Ci, Pj, Cj
  493.   The packet is at Cl..Cm and Pl..Pm.
  494.  
  495.  
  496. I. The attacker choose the packet length to be a multiple of 64-bits, so
  497. the padding will be 64-bits.
  498.  
  499. II. She starts the packet with two cipher blocks: 
  500.     Cl   = X
  501.     Cl+1 = Ci
  502.  
  503. X is choosen to make Pl+1 a block with a valid type and 7-bytes of
  504. selected data. Pl is unknown to the attacker, but its the padding field
  505. of the packet, and is not used in the protocol (except for the crc32
  506. computation).
  507.  
  508. III. The attacker appends 32 64-bits blocks to the cipher stream
  509. Cl+3..Cl+34. Each block is either X (The same choosen in step II) or Ci
  510. in a particular combination that makes the final crc on Pl+3..Pl+34
  511. independent on the value of Dk(X). That is, for each possible value
  512. of Dk(X) the crc of those blocks is the same. 
  513.   This combination exists, and can be found, because of the
  514. characteristics of the crc function mentioned on point 2.
  515.  
  516. IV. The attacker appends 32 64-bits blocks to the cipher stream Cl+35..Cl+67.
  517. Each block is either Ci (Known Ciphertext A) or Cj (known ciphertext B)
  518. making a particular pattern that fix the crc result to the value Pi XOR
  519. Ci (paying attention to the last two blocks appended in step V below). 
  520.  
  521. V. The attacker adds two Ci blocks to the cipherstream appending the
  522. crc32 field to the packet.
  523.   Cm-1 = Ci
  524.   Cm   = Ci
  525.  
  526. The final encrypted packet looks like:
  527.  
  528. X  [block] X/Ci X/Ci X/Ci .... Ci/Cj Ci/Cj Ci/Cj Ci/Cj ... Ci Ci 
  529.  
  530. Where 'block' is the constructed block with type/messagelen/data.
  531.  
  532. C) If CFB-64 mode is used and an attacker has one Pi/Ci Known
  533. plaintext/ciphertext pair she may follow the following steps to
  534. construct a valid packet that will subvert the integrity mechanism.
  535.   The known plaintext/ciphertext pair is Pi/Ci, 'I' is the last block of
  536. the previous packet.
  537.   The new packet is to be inserted at Cl..Cm and Pl..Pm.
  538.  
  539. I. The attacker chooses the packet length to be a multiple of 64-bits, so
  540. the padding will be 64-bits.
  541.  
  542. II. Two blocks are appended to the cipher stream:
  543.  
  544. Cl = Ci
  545. Cl+1 = X
  546.  
  547. The attacker selects X to make Pl+1 a valid type and 7 data bytes block.
  548. Pl is unknown but is entirely contained in the padding field.
  549.  
  550. III. The attacker inserts 32 64-bit blocks to the cipher stream. Each
  551. block is either 'I' or Ci defining a particular pattern that will make the
  552. final crc for the packet independent of Ek(I). This step is needed
  553. because in cfb-64 what is feeded into to the new packet is Ek(I), as 
  554. oppossed to CBC mode where 'I' unencripted is feeded.
  555.  
  556. IV. The attacker appends 32 64-bit blocks to the cipher stream. Each
  557. block is either Ci or X in a particular combination that defines a
  558. pattern for which the CRC on the decrypted stream does not
  559. depend on the value of Dk(X). 
  560.   This is the same process used in Step III of attack B.
  561.     
  562. V. The attacker adds two blocks to end the cipher stream: Ci and Y.
  563. Ci is the ciphertext of the known plain/ciphertext. 
  564. Y is the last block of the cipherstream for that packet, it's directly
  565. XORed to Ek(Ci). She must select Y to make the crc32 field consistent
  566. with the constructed packet. The crc of the packet could be calculated
  567. because it doesnt depend on the unknown Ek(X) value nor on Ek(I).
  568.    
  569. The final packet (encrypted) looks like:
  570.  
  571. Ci  X  Ci/I Ci/I Ci/I .... Ci/X  Ci/X  Ci/X .......... Ci Y
  572.  
  573.  
  574. 5. FINAL CONSIDERATIONS 
  575. ~~~~~~~~~~~~~~~~~~~~~~~
  576. The last two described attacks B, C, defined attacks that inserts 1
  577. selected block of 8 bytes with arbitrary choosen data thru the cipher
  578. stream that decrypts to a valid type/messagelen/data with 3 bytes of
  579. data that will be inserted into the input stream of the running program or
  580. into the client terminal.  More that 3 bytes could be inserted
  581. by appending more than one Ci, X (X, Ci for CBC) pair at the beginning
  582. of the packet, and compensating it's crc later. Most shells include special
  583. meta-characters that could help the attacker deal with 8 unknown
  584. characters between each 8-bytes choosen blocks (i.e. ` or ').
  585.  
  586. The calculation of the X/Ci pattern that doesnt depend on Dk(X) and the
  587. calculation of Ci/Cj for a particular crc can be done easily and
  588. efficiently with basic linear algebra. This doesnt imply 2^32
  589. calculations, although 2^32 is within the power reach of most
  590. microcomputers.
  591.  
  592. The known plaintext/ciphertext pair could easily be found on
  593. ssh-protocol stream given that the attacker knows something about the
  594. terminal type or the destination system that the client is trying to
  595. connect to. SSH includes this kind of information at fixed positions on
  596. particular messages exchanged during the initial negotiation that could be 
  597. identified by its size (the packet length is sent unencrypted on the network 
  598. stream).
  599.   Other sources of known-plaintext are for example the /etc/motd that is
  600. displayed at logon on most unixes. 16 and 8 bytes of known plaintext is
  601. enough for attacks B and C respectively.
  602.  
  603. Attack A is less practical than B and C because the known plaintext
  604. block must be fixed at a particular place within the packet, and it
  605. cannot be extended for more than 4 bytes. However attack A needs no
  606. known plaintext at all.
  607.  
  608. The attacker needs active access to the network stream of the ssh
  609. protocol. That means that she must have access to one machine that's
  610. connected to any segment on the connection's path and has
  611. sniffing/spoofing capabilities on the network.
  612.  
  613.  
  614. 6. REFERENCES
  615. ~~~~~~~~~~~~~
  616.  
  617.   [1] "The SSH (Secure Shell) Remote Login Protocol", T. Ylonen
  618.        Helsinki University of Technology. November 15th 1995
  619.        (draft expired on May 15th, 1996)
  620.  
  621.        Included as the file ./RFC in the ssh distribution
  622.        <http://www.cs.hut.fi/ssh>
  623.  
  624.   [2] "SSH Protocol Architecture", draft-ietf-secsh-architecture-01.txt.gz
  625.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  626.  
  627.   [3] "SSH Connection Protocol", draft-ietf-secsh-connect-03.txt.gz
  628.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  629.  
  630.   [4] "SSH Authentication Protocol", draft-ietf-secsh-userauth-03.txt.gz
  631.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  632.  
  633.   [5] "SSH Transport Layer Protocol",draft-ietf-secsh-transport-03.txt.gz
  634.        T. Ylonen, T. Kivinen, M. Saarinen. SSH. November 7th, 1997 
  635.    
  636.        (drafts expired on May 7th, 1998)
  637.  
  638.   All Internet drafts are available at <ftp://ftp.isi.edu/internet-drafts/>
  639.  
  640.   [6] "Simple Active Attack Against TCP", Laurent Joncheray, 
  641.       Merit Networks Inc., 5th USENIX Security Simposium. 1995.
  642.  
  643.  
  644.   [7] "Problem areas for the IP Security Protocols", Steve Bellovin,
  645.       USENIX 1996. <http://www.research.att.com/~smb/papers/badesp.ps>
  646.  
  647.  
  648.   [8] "On Message Integrity in Cryptographic Protocols",
  649.       S. Stubblebine and V. Gligor, IEEE Computer Society Symposium on
  650.       Research in Security and Privacy, Oakland, CA, May, 1992, pp. 85-104.
  651.  
  652.   [9] "Protocol Design for Integrity Protection", S. Stubblebine and V. Gligor,
  653.       IEEE Computer Society Symposium on Research in Security and Privacy,
  654.       Oakland, CA, May, 1993, pp. 41-53. 
  655.  
  656.  
  657. Additional Information:
  658. ~~~~~~~~~~~~~~~~~~~~~~~
  659.  
  660.    These vulnerabilities were discovered by Ariel Futoransky
  661.    <futo@core-sdi.com> and Emiliano Kargieman <ek@core-sdi.com>
  662.  
  663.    Comments and questions regarding this attack should be sent to:
  664.  
  665.        Ariel Futoransky <futo@core-sdi.com> 
  666.        Emiliano Kargieman <ek@core-sdi.com>
  667.  
  668.    For more information about CORE SDI S.A.  contact <core@core-sdi.com>
  669.    or visit <http://www.core-sdi.com>
  670.     
  671.    You can contact CORE SDI S.A. at <corelabs@core-sdi.com> using the
  672.    the following PGP key:
  673.  
  674. Type Bits/KeyID    Date       User ID
  675. pub  1024/CF4E0CF5 1998/05/18 CORELABS <corelabs@core-sdi.com>
  676.  
  677. -----BEGIN PGP PUBLIC KEY BLOCK-----
  678. Version: 2.6.3ia
  679. Comment: Requires PGP version 2.6 or later.
  680.  
  681. mQCNAzVgfMgAAAEEAJSfJNdvCwIAc4AK0ckeimubLIwzsRVDRhjPQIOYt/7kxxio
  682. DZybr53fwMEjyT8cHXRL08i0R9rcuFeCNAez6XcalbhqUKXDcLL/cZK80CCDSCs5
  683. tRCZGGOEBnXQIoyvbvi4gNYhBS5wUvmh3b/mvRFTvhmRrUy9m/nO/LnPTgz1AAUR
  684. tCBDT1JFTEFCUyA8Y29yZWxhYnNAY29yZS1zZGkuY29tPokAlQMFEDVgfMn5zvy5
  685. z04M9QEBC6ED/0Szt3f54JTvkZG3ezQ8G60HvAw4/A5Ti6i3oze6jsXxzGp6pA1x
  686. i0jaZpKaUSpo0MLc7BcijMKneuUHnN3XtN5YxtFt0aEoot1MIvv4BsdeUb3x257G
  687. 3+vr8SxGk44Vm4tfuN8F/2dNo/00yYP9rd3zQ8Tl+gmr5VxnLViZIDuh
  688. =ulRg
  689. -----END PGP PUBLIC KEY BLOCK-----
  690.  
  691. Copyright Notice:
  692. ~~~~~~~~~~~~~~~~~
  693. The contents of this document are Copyright (C) 1998 CORE SDI S.A.,
  694. and may be distributed freely provided that no fee is charged for
  695. this distribution, and proper credit is given.
  696.  
  697.  
  698. $Id: attack.txt,v 1.2 1998/07/03 21:22:27 iarce Exp $
  699.  
  700.  
  701. ============================================================================
  702.  
  703.                               CORE SDI S.A.
  704.                          Buenos Aires, Argentina
  705.                           <http://www.core-sdi.com>
  706.  
  707.  
  708.                      SSH insertion attack detection
  709. ============================================================================
  710.  
  711.  
  712. Crc32 Compensation attack detector
  713. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  714. This document describes the scope and characteristics of SSH crc32 
  715. compensation attack detector engine. It will inspect an encrypted SSH protocol
  716. 1.5 stream for suspicious patterns. If either the server or client is under
  717. attack, the detector closes the conection and logs the attack.
  718.  
  719.  
  720. Attack characteristics
  721. ~~~~~~~~~~~~~~~~~~~~~
  722. An attacker, with sniffing and spoofing capabilities on the SSH network stream, may perform an active network attack by constructing a packet using a 
  723. known cipher/plaintext pair and computing addditional data to fill the packet
  724. in a way that will produce a valid CRC-32 field and pass as a valid packet when
  725. decryped and integrity checked on the server side.
  726.  If the attack succeeds, arbitrary commands will get executed on the server.
  727.  
  728.   This attack doesnt affect the confidential security characteristics of the
  729. products using this protocols. However, integrity and authentication 
  730. of packets can no longer be trusted.
  731.  
  732. Solution
  733. ~~~~~~~
  734.   This is not an implementation bug, but a protocol design vulnerability. The
  735. protocol must be updated to use cryptographic strong message authentication
  736. codes. SSH Protocol version 2 as published in [1] includes the use of a real
  737. strong MAC.
  738.   However, this will require to update all clients and servers simultaneusly
  739. while disabling compatibility with protocol version 1.5. On many installations
  740. this is not practical.
  741.  
  742.   A mid-term solution exists, that will help protecting the server from the
  743. auth/integrity vulnerabilities.  On most scenarios it will be enough to upgrade
  744. only the servers. 
  745.  
  746.   This approach is based on the fact that an attacker will need to exploit some
  747. of the linear characteristics of the integrity function in order to implement
  748. the attack. In that context, the constructed packets will follow certain 
  749. patterns that could be detected on the encrypted stream.
  750.  
  751.   This is not a general solution, but a countermeasure against a model of all
  752. of the possible attacks that exploits this vulnerabilities. 
  753.  
  754.   The provided patch looks for patterns of repeated ciphered blocks in
  755. each SSH packet received, the performance loss in speed is less 2% in an
  756. uncompressed stream compared to an unpatched server. Memory usage increases 
  757. in about 8k per conection.
  758.   The chances of reporting a false attack in a 32GB file transfer is around
  759. 1 in 2**51.
  760.  
  761. Contact information
  762. ~~~~~~~~~~~~~~~~~~
  763.  
  764.    These vulnerabilities were discovered by Ariel Futoransky
  765.    and Emiliano Kargieman.
  766.  
  767.    Comments and questions regarding this vulnerability and the fix
  768.    should be sent to:
  769.  
  770.        Ariel Futoransky <futo@core-sdi.com>
  771.        Emiliano Kargieman <ek@core-sdi.com>
  772.  
  773.   For more information about CORE SDI S.A.  contact <core@core-sdi.com>
  774.   or visit <http://www.core-sdi.com>
  775.  
  776.   For more information about this problem and related ones visit:
  777.  
  778.    <http://www.core-sdi.com/ssh>
  779.                         
  780.   You can contact CORE SDI S.A. at <corelabs@core-sdi.com> using the
  781.   the following PGP key:
  782.  
  783. -----BEGIN PGP PUBLIC KEY BLOCK-----
  784. Version: 2.6.3ia
  785. Comment: Requires PGP version 2.6 or later.
  786.  
  787. mQCNAzVgfMgAAAEEAJSfJNdvCwIAc4AK0ckeimubLIwzsRVDRhjPQIOYt/7kxxio
  788. DZybr53fwMEjyT8cHXRL08i0R9rcuFeCNAez6XcalbhqUKXDcLL/cZK80CCDSCs5
  789. tRCZGGOEBnXQIoyvbvi4gNYhBS5wUvmh3b/mvRFTvhmRrUy9m/nO/LnPTgz1AAUR
  790. tCBDT1JFTEFCUyA8Y29yZWxhYnNAY29yZS1zZGkuY29tPokAlQMFEDVgfMn5zvy5
  791. z04M9QEBC6ED/0Szt3f54JTvkZG3ezQ8G60HvAw4/A5Ti6i3oze6jsXxzGp6pA1x
  792. i0jaZpKaUSpo0MLc7BcijMKneuUHnN3XtN5YxtFt0aEoot1MIvv4BsdeUb3x257G
  793. 3+vr8SxGk44Vm4tfuN8F/2dNo/00yYP9rd3zQ8Tl+gmr5VxnLViZIDuh
  794. =ulRg
  795. -----END PGP PUBLIC KEY BLOCK-----
  796.  
  797. Copyright
  798. ~~~~~~~~
  799.  
  800. This file, deattack.c and deattack.h  are copyright (c) 1998
  801. CORE SDI S.A., Buenos Aires, Argentina. All rights reserved.
  802. and should be redistributed or modified for non-commercial purposes only
  803. provided that this copyright notice is retained.
  804.  
  805. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES
  806. ARE DISCLAIMED. IN NO EVENT SHALL CORE SDI S.A. BE LIABLE FOR ANY DIRECT,
  807. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES RESULTING
  808. FROM THE USE OR MISUSE OF THIS SOFTWARE.
  809.  
  810.  
  811.